const express = require('express');
const router = express.Router();
const mysql = require('mysql');
const common = require('./common');

const connection = common.mysqlConfig

//执行数据库连接
// connection.connect();

router.post('/', (req, res, next) => {
  const params = {
    staffID: req.headers.token, // 员工 id
    page: (req.body.page - 1) * req.body.size , // （当前页码-1） * 页面大小
    size: req.body.size // 页面大小
  };
  const sql = `SELECT * FROM message_list WHERE userID='${params.staffID}' ORDER BY SENDTIME DESC LIMIT ${params.page},${params.size}`
  connection.query(sql, (err, result) => {
    // 封装公共返回方法
    const data = common.resCommon(err, result);
    res.json(data)
  })
})

module.exports = router;